<?php

namespace api\modules\v1\controllers;
use api\common\controllers\UserController as U;
use Yii;
use yii\web\ServerErrorHttpException;
use yii\web\HttpException;
use yii\web\NotFoundHttpException;
class ThirdController extends U
{
    public $modelClass = 'api\modules\v1\models\Third';


    public function actions()
    {
        $actions = parent::actions();
        unset($actions['index'],$actions['update'], $actions['create'], $actions['delete'], $actions['view']); //卸载操作
        return $actions;
    }

    /*
     * 绑定
     */
    public function actionBind(){
        $model = $this->findModel(Yii::$app->user->identity->id);
        $model->scenario='bind';
        $model->attributes = Yii::$app->request->post();
        if ($model->Bind()) {
            return [
                "message"=>"绑定成功!",
            ];
        }elseif (!$model->hasErrors()) {
            throw new ServerErrorHttpException('由于不明原因未能创建对象.');
        }else{
            throw new HttpException(401,array_values($model->getFirstErrors())[0],0);
        }
    }

    /*
     * 解绑
     */
    public function actionUnbind(){
        $model = $this->findModel(Yii::$app->user->identity->id);
        $model->scenario='unbind';
        $model->attributes = Yii::$app->request->post();
        if ($model->Unbind()) {
            return [
                "message"=>"解绑成功!",
            ];
        }elseif (!$model->hasErrors()) {
            throw new ServerErrorHttpException('由于不明原因未能创建对象.');
        }else{
            throw new HttpException(401,array_values($model->getFirstErrors())[0],0);
        }
    }
}
